public class myStack3 {
    //用双向链表实现栈(头插头删)不带节点不循环
    static class linkedList{
        public int val;
        public linkedList prev;
        public linkedList next;
        public linkedList(int val){
            this.val=val;
        }
    }
    public linkedList head;
    //入栈
    public void push(int val){
        linkedList node=new linkedList(val);
        if(empty()){
            head=node;
        }else{
            node.next=head;
            head.prev=node;
            head=head.prev;
        }
    }
    //出栈
    public int pop(){
        int value=0;
        if(empty()){
            return -1;
        }else{
            if(head.next==null){
                value=head.val;
                head=null;
            }else{
                value=head.val;
                linkedList pcur=head.next;
                head=pcur;
                pcur.prev=null;
            }
        }
        return value;
    }
    //获取栈顶元素
    public int peek(){
        if(empty()){
            return -1;
        }else{
            return head.val;
        }
    }

    //判空
    public boolean empty(){
        return head==null;
    }
}
